package com.hxd.otc.other.rong;

import android.os.Parcel;

import com.hxd.otc.module.order.bean.AllOrderBean;
import com.hxd.otc.utils.GsonUtil;
import com.hxd.otc.utils.LogUtils;

import java.io.UnsupportedEncodingException;

import io.rong.imlib.MessageTag;
import io.rong.imlib.model.MessageContent;

/**
 * Created by lzy on 2018/12/11 0011.
 * description ${订单信息展示消息}
 */
@MessageTag(value = "app:OrderInfoFloatingMessage", flag = MessageTag.ISPERSISTED)
public class OrderInfoFloatingMessage extends MessageContent {
    private AllOrderBean.DataBean mOrderBean;
    private boolean isShow = true;

    public OrderInfoFloatingMessage() {
    }

    public OrderInfoFloatingMessage(AllOrderBean.DataBean orderBean) {
        mOrderBean = orderBean;
    }

    public OrderInfoFloatingMessage(byte[] data) {
        try {
            String jsonStr = new String(data, "UTF-8");
            mOrderBean = GsonUtil.fromJson(jsonStr, AllOrderBean.DataBean.class);
        } catch (UnsupportedEncodingException e) {
            LogUtils.e(e.getMessage());
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(this.mOrderBean, flags);
    }

    @Override
    public byte[] encode() {
        try {
            return GsonUtil.toJson(mOrderBean).getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }

    protected OrderInfoFloatingMessage(Parcel in) {
        this.mOrderBean = in.readParcelable(AllOrderBean.DataBean.class.getClassLoader());
    }

    public static final Creator<OrderInfoFloatingMessage> CREATOR = new Creator<OrderInfoFloatingMessage>() {
        @Override
        public OrderInfoFloatingMessage createFromParcel(Parcel source) {
            return new OrderInfoFloatingMessage(source);
        }

        @Override
        public OrderInfoFloatingMessage[] newArray(int size) {
            return new OrderInfoFloatingMessage[size];
        }
    };

    public void setOrderBean(AllOrderBean.DataBean orderBean) {
        mOrderBean = orderBean;
    }

    public AllOrderBean.DataBean getOrderBean() {
        return mOrderBean;
    }

    public boolean isShow() {
        return isShow;
    }

    public void setShow(boolean show) {
        isShow = show;
    }
}
